import re, requests
import os
import pymysql

# 得到数据库的数据
conn = pymysql.Connect(
            host='localhost',
            port=3306,
            user='root',
            password='root',
            db='hunter',
        )
cursor = conn.cursor()
sql = "select * from data"
cursor.execute(sql)
conn.commit()
datas = cursor.fetchall()

# 下载图片，存储格式
i = 1235
for data in datas[1234:]:
    # 下载图片
    url = data[5]
    res = requests.get(url)
    with open(f"D:\Project\multimoding\data\数据集/{i}.jpg", "wb") as fp:
        fp.write(res.content)
    with open(f"D:\Project\multimoding\data\数据集/{i}.text", "w") as fp:
        data1 = data[4].replace("\n", "")
        data2 = data[3].replace("\n", "")
        fp.write(data1 if data1 != "" else data2)
        print(str(i) + ' ' + str(data[0]))
    i += 1






























